package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
// import cn.dev33.satoken.annotation.SaCheckPermission; // Comment out import
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.ContractManageVo;
import org.dromara.nursing.domain.bo.ContractManageBo;
import org.dromara.nursing.service.IContractManageService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 合同
 *
 * @author Xue
 * @date 2025-04-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/contractManage")
public class ContractManageController extends BaseController {

    private final IContractManageService contractManageService;

    /**
     * 查询合同列表
     */
    // @SaCheckPermission("nursing:contractManage:list")
    @GetMapping("/list")
    public TableDataInfo<ContractManageVo> list(ContractManageBo bo, PageQuery pageQuery) {
        return contractManageService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出合同列表
     */
    // @SaCheckPermission("nursing:contractManage:export")
    @Log(title = "合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ContractManageBo bo, HttpServletResponse response) {
        List<ContractManageVo> list = contractManageService.queryList(bo);
        ExcelUtil.exportExcel(list, "合同", ContractManageVo.class, response);
    }

    /**
     * 获取合同详细信息
     *
     * @param contractId 主键
     */
    // @SaCheckPermission("nursing:contractManage:query")
    @GetMapping("/{contractId}")
    public R<ContractManageVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long contractId) {
        return R.ok(contractManageService.queryById(contractId));
    }

    /**
     * 新增合同
     */
    // @SaCheckPermission("nursing:contractManage:add")
    @Log(title = "合同", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ContractManageBo bo) {
        return toAjax(contractManageService.insertByBo(bo));
    }

    /**
     * 修改合同
     */
    // @SaCheckPermission("nursing:contractManage:edit")
    @Log(title = "合同", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ContractManageBo bo) {
        return toAjax(contractManageService.updateByBo(bo));
    }

    /**
     * 删除合同
     *
     * @param contractIds 主键串
     */
    // @SaCheckPermission("nursing:contractManage:remove")
    @Log(title = "合同", businessType = BusinessType.DELETE)
    @DeleteMapping("/{contractIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] contractIds) {
        return toAjax(contractManageService.deleteWithValidByIds(List.of(contractIds), true));
    }
}
